package com.smallkingson.ylib.net.http;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public final class YConnects {
	private YConnects() {
	}

	public static boolean isConnected(Context context) {
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = manager.getActiveNetworkInfo();
		if (info == null || !info.isConnected()) {
			return false;
		}
		return true;
	}

	public static boolean isConnByWIFI(Context context) {
		ConnectivityManager manager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = manager.getActiveNetworkInfo();
		int type = info.getType();
		if (ConnectivityManager.TYPE_WIFI == type) {
			return true;
		}
		return false;
	}

	/**
	* Reports the type of network to which the
	* info in this {@code NetworkInfo} pertains.
	* @return one of {@link ConnectivityManager#TYPE_MOBILE}, {@link
	* ConnectivityManager#TYPE_WIFI}, {@link ConnectivityManager#TYPE_WIMAX}, {@link
	* ConnectivityManager#TYPE_ETHERNET},  {@link ConnectivityManager#TYPE_BLUETOOTH}, or other
	* types defined by {@link ConnectivityManager}
	*/
	public static int getConnectType(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = connectivityManager.getActiveNetworkInfo();

		if(info==null){
			return -1;
		}
		return info.getType();
	}
}
